/*
*Copyright 2021-2023 NERCIS
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/

package cn.ac.nercis.pes.repository.model.evaluation;

import cn.ac.nercis.pes.common.constant.evaluation.PwdRaCondition;
import cn.ac.nercis.pes.common.constant.evaluation.PwdRkCondition;
import cn.ac.nercis.pes.common.utils.JsonUtils;
import cn.ac.nercis.pes.common.constant.evaluation.EvaluationConclusion;
import cn.ac.nercis.pes.common.constant.evaluation.EvaluationResult;
import cn.ac.nercis.pes.common.constant.project.FinishState;
import cn.ac.nercis.pes.common.constant.project.RefTargetType;
import cn.ac.nercis.pes.repository.constant.BaseConstants;
import cn.ac.nercis.pes.repository.converter.evaluation.EvaluationConclusionConverter;
import cn.ac.nercis.pes.repository.converter.evaluation.EvaluationResultConverter;
import cn.ac.nercis.pes.repository.converter.evaluation.PwdRaConditionConverter;
import cn.ac.nercis.pes.repository.converter.evaluation.PwdRkConditionConverter;
import cn.ac.nercis.pes.repository.converter.project.FinishStateConverter;
import cn.ac.nercis.pes.repository.converter.project.RefTargetTypeConverter;
import cn.ac.nercis.pes.repository.model.base.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.GenericGenerator;

/**
 * 现场测评记录信息实体类
 * @author zpy
 * @version 1.0.0
 */
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "pes_evaluation_record")
public class EvaluationRecordDO extends BaseEntity {
    @Id
    @GenericGenerator(name = "generator",strategy = BaseConstants.CUSTOM_UUID_STRATEGY)
    @GeneratedValue(generator = "generator")
    @Column(name = "id",unique = true,nullable = false,length = 36)
    private String id;

    @Column(name = "system_id",nullable = false,length = 36)
    private String systemId;
    @Column(name = "layer_target_id",nullable = false,length = 36)
    private String layerTargetId;
    @Column(name = "unit_target_id",nullable = false,length = 36)
    private String unitTargetId;
    @Column(name = "asset_evaluation_method_id",nullable = false,length = 36)
    private String assetEvaMethodId;

    @Convert(converter = EvaluationConclusionConverter.class)
    @Column(name = "conclusion",nullable = false)
    private EvaluationConclusion conclusion;

    @Convert(converter = EvaluationResultConverter.class)
    @Column(name = "d_result",nullable = false)
    private EvaluationResult dResult;
    @Convert(converter = EvaluationResultConverter.class)
    @Column(name = "a_result",nullable = false)
    private EvaluationResult aResult;

    @Convert(converter = PwdRaConditionConverter.class)
    @Column(name = "a_condition")
    private PwdRaCondition aCondition;

    @Convert(converter = EvaluationResultConverter.class)
    @Column(name = "k_result",nullable = false)
    private EvaluationResult kResult;

    @Convert(converter = PwdRkConditionConverter.class)
    @Column(name = "k_condition")
    private PwdRkCondition kCondition;

    @Column(name = "d_content",length = 2000)
    private String dContent;
    @Column(name = "a_content",length = 2000)
    private String aContent;
    @Column(name = "k_content",length = 2000)
    private String kContent;
    @Column(name = "content",length = 2000)
    private String content;

    @Column(name = "d_files",length = 500)
    private String dFiles;
    @Column(name = "a_files",length = 500)
    private String aFiles;
    @Column(name = "k_files",length = 500)
    private String kFiles;
    @Column(name = "manage_files",length = 500)
    private String manageFiles;

    @Column(name = "score")
    private Double score;

    @Convert(converter = FinishStateConverter.class)
    @Column(name = "finish_state",nullable = false)
    private FinishState finishState;

    @Builder.Default
    @Convert(converter = RefTargetTypeConverter.class)
    @Column(name = "ref_type", nullable = false)
    private RefTargetType refType = RefTargetType.STANDARD;

    @ManyToOne(cascade = {CascadeType.REFRESH},optional = false)
    @JoinColumn(name = "asset_id")
    private AssetDO asset;

    @Override
    public String toString() {
        return this.getClass().getSimpleName().concat(JsonUtils.toJson(this));
    }

}